
var EDT_PRFS={
  tabobjs:[],
  printhook: 0
};


EDT_PRFS.personal = function() {
  /*
  var html="";
  html+="<BR><TABLE>";
  html+="<TR><TH align=left> Signature </TH><TD><input type=text value='"+GetPrefsSignature()+"' ";
  html+="onChange='SetPrefsSignature(this.value);' size=20></TD></TR>";
  
  // html+="<TR><TH align=left> Productivity Factor </TH><TD><input type=text value='"+GetPrefsProdFactor()+"' ";
  //html+="onChange='SetPrefsProdFactor(this.value);' ></TD></TR>";
  html+="<TR><TH align=left> Enable Experimental Features </TH><TD><input type=checkbox "+(GetPrefsDebugging() ? "checked":"")+" ";
  html+="onChange='SwitchPrefsDebugging();'></TD></TR>";
  html+="</TABLE>";
  return html+EDT_PRFS.locale();
  */


  var html="<TABLE>";
  html+="<TR><TH align=left><fieldset><legend> Signature</legend><input type=text value='"+GetPrefsSignature()+"' ";
  html+="onChange='SetPrefsSignature(this.value);' size=35></fieldset></TH></TR><TR>";  
  html+="<TH align=left><fieldset><legend>Langages</legend><TABLE width=100%><TR>";
  var l_iter= new lang_iterator();
  while(!l_iter.end()) {
    html+="<TD align=left>"+l_iter.getValue()+"</TD><TD align=right><input type=checkbox checked></TD>";
    //eval("f=function() { return EDT_PRFS.keywords('"+l_iter.getValue()+"')}"); 
    //EDT_PRFS.langobjs[l_iter.getValue()]={ callback:  f};
    l_iter.next();
  }
  html+="<TD><input type=text size=2><input type=button value='+'></TD></TR></TABLE></fieldset></TR><TR>";
  html+="<TH align=left><fieldset><legend>Laws</legend><TABLE width=100%><TR>";
  var l_iter= new law_iterator();
  while(!l_iter.end()) {
    html+="<TD align=left>"+l_iter.getValue()+"</TD><TD align=right> <input type=checkbox checked></TD>";
    l_iter.next();
  }
  html+="<TD><input type=text size=2><input type=button value='+'></TD></TR></TABLE></fieldset></TD></TR>";
  
 html+="</TABLE>";

  return html;
}

EDT_PRFS.interface = function() {
  var html="<TABLE>";
  html+="<TR><TH align=left>Load last file on starting</TH><TD><input type=checkbox "+(GetPrefsAttr("startload") ? "checked":"")+" ";
  html+="onChange='SwitchPrefsAttr(\"startload\");'></TD></TR>";

  html+="<TR><TH align=left> Max claims per page </TH><TD><input type=text value='"+GetMaxClaimsPerPage()+"' ";
  html+="onChange='SetMaxClaimsPerPage(this.value);this.value=GetMaxClaimsPerPage();' size=40 ></TD></TR>";
  
  html+="<TR><TH align=left> Max recent files </TH><TD><input type=text value='"+ GetMaxPrefsDossier()+"' ";
  html+="onChange='SetMaxPrefsDossier(this.value);this.value=GetMaxPrefsDossier();' size=40 ></TD></TR>";
  html+="<TR><TH align=left> Enable Experimental Features </TH><TD><input type=checkbox "+(GetPrefsDebugging() ? "checked":"")+" ";
  html+="onChange='SwitchPrefsDebugging();'></TD></TR>";
  
  html+="</TABLE>";
  return html;
}

EDT_PRFS.keywordfill=function(lang,kw) {
  //alert(lang+" "+kw);
  document.getElementById("add"+lang).value=kw;
}

EDT_PRFS.keywords=function(lang){
  var kw_iter=new kwname_iterator("skipkeyword",lang);
  var html="<table>";
  while(!kw_iter.end()) {
    html+="<TR><TD onmouseover='EDT_PRFS.keywordfill(\""+lang+"\",\""+kw_iter.getValue()+"\")'>"+kw_iter.getValue()+"</TD><TR>";
    kw_iter.next();
  }

  html+="</table>";
  return html;
}

EDT_PRFS.langobjs=[];
EDT_PRFS.locale = function() {
  var f;
  var html="<h3>Globals</h3><TABLE><TR><TD>";
  html+="<TABLE border=1><TR><TH align=left colspan=3> Langages </TH></TR><TR>";
  var l_iter= new lang_iterator();
  while(!l_iter.end()) {
    html+="<TD>"+l_iter.getValue()+" <input type=checkbox ></TD>";
    eval("f=function() { return EDT_PRFS.keywords('"+l_iter.getValue()+"')}"); 
    EDT_PRFS.langobjs[l_iter.getValue()]={ callback:  f};
    l_iter.next();
  }
  html+="<TD><input type=text size=2><input type=button value='+'></TD></TR></TABLE></TD>";
  html+="<TD><table  border=1><TR><TH align=left colspan=3> Laws </TH></TR><TR>";
  var l_iter= new law_iterator();
  while(!l_iter.end()) {
    html+="<TD>"+l_iter.getValue()+" <input type=checkbox ></TD>";
    l_iter.next();
  }
  html+="<TD><input type=text size=2><input type=button value='+'></TD></TR></table></TD></TR>";
  html+="</TABLE>";
  return html;
}

EDT_PRFS.diff = function() {

  var html="<h3>Ignore characters</h3>";
  html+="<table border=1><TR><TH> . </TH><TH> ; </TH> <TH> , </TH><TH> : </TH></TR><TR>";  
  html+="<TD><input type=checkbox ></TD>";
  html+="<TD><input type=checkbox ></TD>";
  html+="<TD><input type=checkbox ></TD>";
  html+="<TD><input type=checkbox ></TD>";
  html+="</TR></TABLE>";

  html+="<h3>Ignore words</h3>";
  var l_iter= new lang_iterator();
  html+="<table border=1><TR>";
  while(!l_iter.end()) {
    html+="<TH>"+l_iter.getValue()+"</TH>";
    l_iter.next();
  }
  html+="</TR><TR>";
  var l_iter= new lang_iterator();
  var tabs=[];
  var addhtml="";
  while(!l_iter.end()) {    
    addhtml+="<TD><input type=text size=20 id='add"+l_iter.getValue()+"'><input type=button value='+'></TD>";
    html+="<TD valign=top>"+EDT_PRFS.keywords(l_iter.getValue())+"</TD>";
    l_iter.next();
  }
  html+="</TR><TR>"+addhtml+"</TR></Table>";
  
  /*
  eval("f=function() { return EDT_PRFS.keywords('"+l_iter.getValue()+"')}"); 
  EDT_PRFS.langobjs[l_iter.getValue()]={ callback:  f};
  l_iter.next();
  html+=html_tabs_obj("langs",EDT_PRFS.langobjs)
  */
  return html;
}

EDT_PRFS.files = function() {
  var html="<TABLE>";  
  html+="<TR><TH align=left> OCR Files dir </TH><TD><input type=text value='"+GetPrefsOCRFilesDir()+"' ";
  html+="onChange='SetPrefsOCRFilesDir(this.value);this.value=GetPrefsOCRFilesDir();' size=80></TD></TR>";

  html+="<TR><TH align=left> Default OCR File  </TH><TD><input type=text value='"+GetPrefsOCRFile()+"' ";
  html+="onChange='SetPrefsOCRFile(this.value);this.value=GetPrefsOCRFile();' size=80></TD></TR>";

  html+="<TR><TH align=left> Use Utf-8 Decoding </TH><TD><input type=checkbox "+(GetPrefsAttr("utf8") ? "checked":"")+" ";
  html+="onChange='SwitchPrefsAttr(\"utf8\");'></TD></TR>";
  

  html+="<TR><TH align=left> Trimaran </TH><TD><input type=checkbox "+(GetPrefsAttr("trimaran") ? "checked":"")+" ";
  html+="onChange='SwitchPrefsAttr(\"trimaran\");'></TD></TR>";

  html+="<TR><TH align=left> Default Caesar Directory  </TH><TD><input type=text value='"+GetPrefsCaesarDir()+"' ";
  html+="onChange='SetPrefsCaesarDir(this.value);this.value=GetPrefsCaesarDir();' size=80></TD></TR>";
  html+="</TABLE>";
  return html;
}

EDT_PRFS.categories = function() {
  var html="<TABLE border=1>";  
  var kw_iter=new kw_iterator("@usrcat=\"yes\"");
  html+="<TR><TH>Use</TH><TH>Tag</TH><TH>Name</TH><TH colspan=2>Colors</TH><TH>1!</TH>";
  var l_iter= new lang_iterator();
  while(!l_iter.end()) {    
    html+="<TH>Keywords<BR>"+l_iter.getValue()+"</TH>";
    l_iter.next();
  }
  html+="</TR>";
  while(!kw_iter.end()) {
    html+="<TR>";
    html+="<TD align=center><input type=checkbox "+(kw_iter.isActive() ? "checked":"");
    html+=" onChange='kw_SwitchActiveCat(\""+kw_iter.getCat()+"\");'></TD>";
    html+="<TD align=center>"+kw_iter.getCat()+"</TD><TD>"+tofirstcapital(kw_iter.getCatName("en"))+"</TD>";
    html+="<TD class='CLINDEP "+kw_iter.getColor1()+"'>"+kw_iter.getCat()+"</TD>";
    html+="<TD class='CLDEP "+kw_iter.getColor2()+"'>2</TD>";
    html+="<TD align=center><input type=checkbox "+(kw_iter.isCatMaxOne() ? "checked":"");
    html+=" onChange='kw_SwitchCatMaxOne(\""+kw_iter.getCat()+"\");'></TD>";
    var l_iter= new lang_iterator();
    while(!l_iter.end()) {    
      var kwkw_iter= kw_iter.keywords(l_iter.getValue());
       html+="<TD>"+html_selection_iter("kwkws",kwkw_iter,"","","","","------------------------------------")+"</TD>";
      /*
      while(!kwkw_iter.end()) {
	html+="<TD>"+kwkw_iter.getValue()+"</TD>";
	kwkw_iter.next();
      }
      html+="</TR></TABLE></TD>";*/
      l_iter.next();
    }
    html+="<TD><button onclick='' class='FULL' >"+html_img(edit_img)+"</button></TD>";
    html+="</TR>";
    kw_iter.next();
  }
  html+="<TR><BR></TR>";
  html+="<TR><TD><BUTTON TYPE=Button onclick='' ACCESSKEY='A'>"+html_img(add_img)+"</button></TD>";
  html+="<TD><input type=text size=1></TD><TD><input type=text size=10></TD><TD></TD><TD></TD>";
  html+="<TD align=center><input type=checkbox ></TD>";
  html+="<TD><input type=text size=25></TD>";
  html+="<TD><input type=text size=25></TD>";
  html+="<TD><input type=text size=25></TD>";
  html+="</TR>";
 
  html+="</TABLE>";
  return html;
}

EDT_PRFS.tabobjs["Personal"]={callback:EDT_PRFS.personal};
EDT_PRFS.tabobjs["Interface"]={callback:EDT_PRFS.interface};
EDT_PRFS.tabobjs["Files"]={callback:EDT_PRFS.files};
EDT_PRFS.tabobjs["Diff Tool"]={callback:EDT_PRFS.diff};
EDT_PRFS.tabobjs["Claim Categories"]={callback:EDT_PRFS.categories};

function edit_prefs() {
  ACT_MOD=EDT_PRFS;
  var title="<h3><BUTTON TYPE=Button onclick='save_dossier();' ACCESSKEY='S'>";
  title+=html_img(section_img)+"</BUTTON> Edit preferences </h3>";
  html_display(title+html_tabs_obj("prefs",EDT_PRFS.tabobjs));
}
